;未排地雷个数
    MINE_LEFT       DB  0H
    ;实际三个表的长宽,总雷数
    REAL_WIDTH           DB  0H
    REAL_HEIGHT          DB  0H
    MINE_NUM        DB  0H
    ;难度，分为三个等级:分别为0,1,2
    ;A.10*20,10个雷
    ;B.20*40,40个雷
    ;C.20*40,80个雷
    HARD_LEVEL      DB  0H

;MOV AX,MINE_TABLE
;MOV DS,AX
;MOV SI,1200
;MOV CX 2400
;CLD
;REP MOVSB

;MINE_TABLE_NEW   DB  40*60  DUP(0H)
;MOV MINE_TABLE,MINE_TABLE_NEW      ;初始化


MINE_TABLE_GENERATE PROC
    PUSH AX
    PUSH BX
    PUSH CX
    PUSH DX
    PUSH SI
    PUSH DS
    MOV CX, MINE_NUM 
    DEC CX
    NEXT: GET_RAND REAL_WIDTH,AL ;产生从1到行数WIDTH之间的随机数作为雷的x坐标
          GET_RAND REAL_HEIGHT,BL ;产生从1到行数HEIGHT之间的随机数作为雷的y坐标
          MOV SI,BL
          MUL 60
          ADD SI,AX
          DEC SI ;产生偏移地址
          CMP  MINE_TABLE[SI],0
          JC NEXT1  ;若不大于，转向NEXT1
          JMP NEXT  ;否则，转到NEXT
          ;检查是否重复坐标
          NEXT1: MOV MINE_TABLE[SI],1
                 JMP LOOP41
    LOOP41 NEXT

    POP DX
    POP CX
    POP BX
    POP AX
    POP DS
    POP SI
MINE_TABLE_GENERATE ENDP









;判断表，记录第i行第j列的元素四周雷的个数,取值0~8,初始化
JUDGE_TABLE_GENERATE PROC
    PUSH AX
    PUSH BX
    PUSH CX
    PUSH DX
    PUSH SI
    PUSH DS
    
    MOV AX,MINE_TABLE   ;在judge table中分别把每个雷周围的数字加1
    MOV DS,AX
    MOV SI,0
    MOV CX,MINE_NUM
    LOOP_JUDGE_NUM: 
     MOV DH,x[SI]
     MOV DL,y[SI]
     CALL ARER1
     CALL ARER2
     CALL ARER3
     CALL ARER4
     CALL ARER5
     CALL ARER6
     CALL ARER7
     CALL ARER8
     INC SI
    LOOP LOOP_JUDGE_NUM

    JMP JUDGE_END  ;直接结束judge

    ARER1:
     CMP DH,1
     JB JU_1
     CMP DL,2
     JB JU_1
     MOV BX,DX
     DEC BH
     SUB BL,2
     CALL MUL_POSITION
     JU_1: NOP
     RET

    ARER2:
     CMP DH,1
     JB JU_2
     MOV BX,DX
     DEC BH
     CALL MUL_POSITION
     JU_2: NOP
     RET

    ARER3:
     CMP DH,1
     JB JU_3
     CMP DL,16
     JA JU_3
     MOV BX,DX
     DEC BH
     ADD BL,2
     CALL MUL_POSITION
     JU_3: NOP
     RET

    ARER4:
     CMP DL,2
     JB JU_4
     MOV BX,DX
     SUB BL,2
     CALL MUL_POSITION
     JU_4: NOP
     RET

    ARER5:
     CMP DL,16
     JA JU_5
     MOV BX,DX
     ADD BL,2
     CALL MUL_POSITION
     JU_5: NOP
     RET

    ARER6:
     CMP DH,8
     JA JU_6
     CMP DL,2
     JB JU_6
     MOV BX,DX
     INC BH
     SUB BL,2
     CALL MUL_POSITION
     JU_6: NOP
     RET

    ARER7:
     CMP DH,8
     JA JU_7
     MOV BX,DX
     INC BH
     CALL MUL_POSITION
     JU_7: NOP
     RET

    ARER8:
     CMP DH,8
     JA JU_8
     CMP DL,16
     JA JU_8
     MOV BX,DX
     INC BH
     ADD BL,2
     CALL MUL_POSITION
     JU_8: NOP
     RET

    MUL_POSITION:  ;获得MINE_TABLE中的位置
     MOV AL,20
     MUL BH
     MOV BH,0
     ADD AX,BX
     MOV BX,AX
     MOV AL,DS:[BX]
     CMP AL,1
     JE FINISHM
     INC AL
     MOV DS:[BX],AL
    
    FINISHM:  RET

    JUDGE_END: POP DS
               POP SI
               POP DX
               POP CX
               POP BX
               POP AX
               RET

JUDGE_TABLE_GENERATE ENDP










